import { $http } from '@/utils';
import { $ResponseCode } from '@/utils/const/env';
export const Technician = {
    list: (query: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Technician/list', {
                data: query
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    details: (technician_id: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Technician/details', {
                data: {
                    technician_id
                }
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    getServiceTime: (technician_id: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Technician/getServiceTime', {
                data: {
                    technician_id
                }
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });

            })
        })
    },
    info: () => {
        return new Promise((resolve, reject) => {
            $http.get('Technician/info').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    deleteTechnicianImage: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Technician/deleteTechnicianImage', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    apply: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Technician/apply', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    getDistance: (query: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Technician/getDistance', {
                data: query
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    statistics(query: any) {
        return new Promise((resolve, reject) => {
            $http.get('Technician/statistics', {
                data: query
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    recommendExchange(data: any) {
        return new Promise((resolve, reject) => {
            $http.post('Technician/recommendExchange', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });

            })
        })

    },
    shop() {
        return new Promise((resolve, reject) => {
            $http.get('Technician/shop').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });

            })
        })

    },
    updateLocation(data: any) {
        return new Promise((resolve, reject) => {
            $http.post('Technician/updateLocation', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });

            })
        })
    },
    toggleResting() {
        return new Promise((resolve, reject) => {
            $http.get('Technician/toggleResting').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });

            })
        })
    }
}